﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using Common.Core.Objects;

namespace Common.Core.Configuration
{
	public class ConfigurationElementCollection<ItemType> : ConfigurationElementCollection
		where ItemType : ConfigurationElement, IObjectWithKey, new()
	{
		protected override ConfigurationElement CreateNewElement()
		{
			return new ItemType();
		}

		protected override object GetElementKey( ConfigurationElement element )
		{
			IObjectWithKey item = element as IObjectWithKey;
			if ( item != null )
			{
				return item.Key;
			}
			throw new InvalidOperationException( "The specified element does not implement IObjectWithKey." );
		}
	}
}
